﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ActionWithCollection.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   Defines the ActionWithCollection type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.Saf.Tests.Support.Actions
{
    using System.Collections.Generic;

    using Engine;

    using Entities;

    /// <summary>
    /// </summary>
    public class ActionWithCollection : ActionBase<Person>
    {
        public ActionWithCollection() { }

        SafContext safContext;

        protected override ProcessStatus  DoAction(SafContext context, Person person)
        {
            this.safContext = context;
            string x = person.Forename;

            List<Person> peopleList = this.GetPersonList(context);
            peopleList.Add(person);

            this.safContext.ActionProperties.Add("People", peopleList, true);
            return ProcessStatus.Success;
        }

        private List<Person> GetPersonList(SafContext ctxt)
        {
            
            List<Person> personList = ctxt.ActionProperties.Get<List<Person>>("People");
            if (personList == null)
                return new List<Person>();
            
            return personList;
        }




        /*
        /// <summary>
        /// Return the name of this Action
        /// </summary>
        /// <returns></returns>
        public override string Name
        {
            get
            {
                return "Collaboris.SharePoint.Libary.Tests.Support.Actions.SimpleActionNoException";
            }
        }
*/


        protected override ProcessStatus UndoAction(SafContext context, Person person)
        {
            this.safContext = context;
            string x = person.Forename;

            List<Person> peopleList = this.GetPersonList(context);
            peopleList.Add(person);

            this.safContext.ActionProperties.Add("People", peopleList, true);

            return ProcessStatus.Success;
        }
    }
}